#include "bluejproject.h"

BlueJProject::BlueJProject()
{
}

BlueJProperty::BlueJProperty(const QString &name) :
        _name(name)
{

}

void BlueJProject::appendProperty(BlueJProperty property)
{
    this->_properties.append(property);
}

QString BlueJProject::text()
{
    QString text = "#BlueJ package file\n";

    foreach (BlueJProperty property, this->_properties) {
        text += property.text();
    }

    return text;
}

void BlueJProject::setPath(const QString &path)
{
    this->_path = path;
}

void BlueJProject::write()
{
    QFile blueJFile(this->_path + "/package.bluej");
    blueJFile.open(QIODevice::WriteOnly);
    blueJFile.write(this->text().toAscii());
    blueJFile.close();
}

void BlueJProperty::appendAttribute(const QString &name, const QString &value)
{
    QString line = QString("%1.%2=%3")
                   .arg(this->_name)
                   .arg(name)
                   .arg(value);

    this->_properties.append(line);
}

QString BlueJProperty::text()
{
    QString text = "";

    foreach (QString line, this->_properties) {
        text += line + "\n";
    }

    return text;
}
